//指标分类管理
/* eslint-disable */
import React, { Component } from 'react';
import { connect } from 'dva';
import { Table, Divider, Tag, InputNumber, Input, Select, Button, message, Icon } from 'antd';
import styles from './Dbcspz.less';
import Filtrate from '../../components/common/Filtrate';
import MyPagination from '../../components/common/MyPagination';
import Container from '../../components/common/Container';
import MyTable from '../../components/common/MyTable';
import request from '../../utils//request';
import PublicService from "../../services/PublicService";
import AddModal from './sub/AddModal';
import config from '../../config';
const { Search } = Input;
const { Option } = Select;
let dragingIndex = -1;
const IconFont = Icon.createFromIconfontCN({
    scriptUrl: '//at.alicdn.com/t/font_1589202_7c747i8xu6h.js',
});

class Dbcspz extends Component {
    state = {
        type:'',
        id: '',
        footerShow: true,
        modalTitle: '',
        addModal: false,
        loading: false,
        icTwoId: '',
        options: [],//指标下拉框
        dataSource: [{}],
        dataSource_whnh:[{}],
        dataSource_dndh:[{}],
        params: {},
        pageSize: 10,
        pageIndex: 1,
        total: 0,
        columns: [
            {
                children: [
                    {
                        title: '指标单位',
                        dataIndex: 'addTheDate',
                        // key: 'addTheDate',
                        width: 100,
                        align: 'center',
                    },

                ],
                title: '指标名称',
            },
            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'ljjcl',
                        // key: 'ljjcl',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '垃圾进场量',
            }, {
                dataIndex: 'xbcw',
                children: [
                    {
                        title: 't',
                        dataIndex: 'ljrll',
                        // key: 'ljrll',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '垃圾焚烧量',
            }, {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'fdl',
                        // key: 'fdl',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '发电量',
            }, {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'swdl',
                        // key: 'swdl',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '上网电量',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'fscydl',
                        // key: 'fscydl',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '非生产用电量',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'fscydl2',
                        // key: 'fscydl2',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '非生产用电率',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'fdcydl',
                        // key: 'fdcydl',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '发电厂用电量',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'fdcydl2',
                        // key: 'fdcydl2',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '发电厂用电率',
            },


            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'zhcydl',
                        // key: 'zhcydl',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '综合厂用电量',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'zhcydl2',
                        // key: 'zhcydl2',
                        width: 120,
                        align: 'center',
                    },

                ],
                title: '综合厂用电率',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'sdl',
                        // key: 'sdl',
                        width: 100,
                        align: 'center',
                    },

                ],
                title: '受电量',
            },
            {
                dataIndex: 'id',
                title: '操作',
                // key: 'id9',
                width: 120,
                align: 'center',
                render: (text, record, index) => {
                    return (

                        <span>
                            <a src="javascript:" onClick={this.onPrint.bind(this,record,'经济指标')}>编辑</a>
                        </span>
                    )
                }
            }
        ],
        columns_dcdh: [
            {
                children: [
                    {
                        title: '指标单位',
                        dataIndex: 'addTheDate',
                        // key: 'addTheDate',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '指标单位',
            },
            {
                children: [
                    {
                        title: 'KWh/t',
                        dataIndex: 'ljfdl',
                        // key: 'ljfdl',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾发电量',
            }, {
                dataIndex: 'xbcw',
                children: [
                    {
                        title: 't/t',
                        dataIndex: 'ljhyl',
                        // key: 'enterFurnace',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾耗油量',
            }, {
                children: [
                    {
                        title: 'KWh/t',
                        dataIndex: 'ljhdl',
                        // key: 'electricity',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾耗电量',
            }, {
                children: [
                    {
                        title: 'KWh/t',
                        dataIndex: 'ljhsl',
                        // key: 'onGridEnergy',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾耗水量',
            },


            {
                children: [
                    {
                        title: 't/t',
                        dataIndex: 'ljhxthl',
                        // key: 'synthesize',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾活性炭耗量',
            },
            {
                children: [
                    {
                        title: 't/t',
                        dataIndex: 'ljqyhghl',
                        // key: 'byThePower',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾氢氧化钙耗量',
            },
            {
                children: [
                    {
                        title: 't/t',
                        dataIndex: 'ljzhjhl',
                        // key: 'byThe1Power',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾蛰合剂耗量',
            },
            {
                children: [
                    {
                        title: 't/t',
                        dataIndex: 'ljlzcl',
                        // key: 'byTheP2ower',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾炉渣耗量',
            },
            {
                children: [
                    {
                        title: 't/t',
                        dataIndex: 'ljfhcl',
                        // key: 'byTh3ePower',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '吨垃圾飞灰耗量',
            },
            {
                dataIndex: 'id',
                title: '操作',
                // key: 'id9',
                width: 100,
                align: 'center',
                render: (text, record, index) => {
                    return (

                        <span>
                            <a src="javascript:" onClick={this.onPrint.bind(this,record,'单产单耗')}>编辑</a>
                        </span>
                    )
                }
            }
        ],
        columns_whnh: [
            {
                children: [
                    {
                        title: '指标单位',
                        dataIndex: 'addTheDate',
                        // key: 'addTheDate',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '指标单位',
            },
            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'rysyl',
                        // key: 'rubbish',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '燃油使用量',
            }, {
                dataIndex: 'xbcw',
                children: [
                    {
                        title: 't',
                        dataIndex: 'szysyl',
                        // key: 'enterFurnace',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '水资源使用量',
            }, {
                children: [
                    {
                        title: 't',
                        dataIndex: 'qyhgsyl',
                        // key: 'electricity',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '氢氧化钙使用量',
            }, {
                children: [
                    {
                        title: 't',
                        dataIndex: 'hxtsyl',
                        // key: 'onGridEnergy',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '活性炭使用量',
            },


            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'zhjsyl',
                        // key: 'synthesize',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '蛰合剂使用量',
            },
            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'lzcl',
                        // key: 'byThePower',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '炉渣产量',
            },
            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'fhcl',
                        // key: 'byThe1Power',
                        width: 130,
                        align: 'center',
                    },

                ],
                title: '飞灰产量',
            },

            {
                dataIndex: 'id',
                title: '操作',
                // key: 'id9',
                width: 100,
                align: 'center',
                render: (text, record, index) => {
                    return (

                        <span>
                            <a src="javascript:" onClick={this.onPrint.bind(this,record,'物耗能耗')}>编辑</a>
                        </span>
                    )
                }
            }
        ],
    };

    componentDidMount() {
        // this.onSubmit(1, 10)
        this.getList()//经济指标
    }

    getList = () => {
        request({
            url: '/sx-client/sx/jjzbConfig/getList',
            method: 'GET',
        }).then(data => {
            if (data.rc === 0) {
                data.ret[0].addTheDate = '行业标杆值'
                this.setState({
                    dataSource: data.ret
                })
            }

        })

        request({
            url: '/sx-client/sx/whnhzbConfig/getList',
            method: 'GET',
        }).then(data => {
            if (data.rc === 0) {
                data.ret[0].addTheDate = '行业标杆值'
                this.setState({
                    dataSource_whnh: data.ret
                })
            }

        })

        request({
            url: '/sx-client/sx/dcdhzbconfig/getList',
            method: 'GET',
        }).then(data => {
            if (data.rc === 0) {
                data.ret[0].addTheDate = '行业标杆值'
                this.setState({
                    dataSource_dndh: data.ret
                })
            }

        })
    }





    onSubmit = (page, size) => {//查询
        const params = this.f1.getForm().getFieldsValue();
        params.page = page;
        params.rows = size;
        params.monthStr = params.monthStr.valueOf()


        this.setState({
            params
        })


        request({
            url: '/sx-client/sx/indicator/fillInFromPagingQuery',
            method: 'POST',
            data: params
        }).then(data => {
            console.log(data)
            if (data.rc === 0) {
                this.setState({
                    dataSource: data.ret.items,
                    total: data.ret.count,
                    params
                })
            } else {
                message.warning(`${data.err}`)
            }
        })

    }

    // 查看按钮
    onPrint = (record,v) => {
        if(v == '经济指标'){
            this.setState({
                moddleArr: [
                    {
                        type: 'input',
                        label: "垃圾进场量",
                        paramName: "ljjcl",
                        // key: "ljjcl",
                        initialValue: record.ljjcl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                        // span: 24
                    },
                    {
                        type: 'input',
                        label: "垃圾焚烧量",
                        paramName: "ljrll",
                        // key: "ljrll",
                        initialValue: record.ljrll,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "发电量",
                        paramName: "fdl",
                        // key: "fdl",
                        initialValue: record.fdl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "上网电量",
                        paramName: "swdl",
                        // key: "swdl",
                        initialValue: record.swdl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "非生产用电量",
                        paramName: "fscydl",
                        // key: "fscydl",
                        initialValue: record.fscydl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "非生产用电率",
                        paramName: "fscydl2",
                        // key: "fscydl2",
                        initialValue: record.fscydl2,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "发电厂用电量",
                        paramName: "fdcydl",
                        // key: "fdcydl",
                        initialValue: record.fdcydl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "非生产用电率",
                        paramName: "fscydl2",
                        // key: "fscydl2",
                        initialValue: record.fscydl2,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "发电厂用电率",
                        paramName: "fdcydl2",
                        // key: "fdcydl2",
                        initialValue: record.fdcydl2,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "综合厂用电量",
                        paramName: "zhcydl",
                        // key: "zhcydl",
                        initialValue: record.zhcydl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "综合厂用电率",
                        paramName: "zhcydl2",
                        // key: "zhcydl2",
                        initialValue: record.zhcydl2,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "受电量",
                        paramName: "sdl",
                        // key: "sdl",
                        initialValue: record.sdl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                ]
            })

        }

        if(v == '单产单耗'){
            this.setState({
                moddleArr: [
                    {
                        type: 'input',
                        label: "吨垃圾发电量",
                        paramName: "ljfdl",
                        // key: "ljfdl",
                        initialValue: record.ljfdl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                        // span: 24
                    },
                    {
                        type: 'input',
                        label: "吨垃圾耗油量",
                        paramName: "ljhyl",
                        // key: "ljhyl",
                        initialValue: record.ljhyl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾耗电量",
                        paramName: "ljhdl",
                        // key: "ljhdl",
                        initialValue: record.ljhdl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾耗水量",
                        paramName: "ljhsl",
                        // key: "ljhsl",
                        initialValue: record.ljhsl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾活性炭耗量",
                        paramName: "ljhxthl",
                        // key: "ljhxthl",
                        initialValue: record.ljhxthl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾氢氧化钙耗量",
                        paramName: "ljqyhghl",
                        // key: "ljqyhghl",
                        initialValue: record.ljqyhghl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾蛰合剂耗量",
                        paramName: "ljzhjhl",
                        // key: "ljzhjhl",
                        initialValue: record.ljzhjhl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾炉渣耗量",
                        paramName: "ljlzcl",
                        // key: "ljlzcl",
                        initialValue: record.ljlzcl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "吨垃圾飞灰耗量",
                        paramName: "ljfhcl",
                        // key: "ljfhcl",
                        initialValue: record.ljfhcl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    }
                ]
            })

        }

        if(v == '物耗能耗'){
            this.setState({
                moddleArr: [
                    {
                        type: 'input',
                        label: "燃油使用量",
                        paramName: "rysyl",
                        // key: "rysyl",
                        initialValue: record.rysyl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                        // span: 24
                    },
                    {
                        type: 'input',
                        label: "水资源使用量",
                        paramName: "szysyl",
                        // key: "szysyl",
                        initialValue: record.szysyl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "氢氧化钙使用量",
                        paramName: "qyhgsyl",
                        // key: "qyhgsyl",
                        initialValue: record.qyhgsyl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "活性炭使用量",
                        paramName: "hxtsyl",
                        // key: "hxtsyl",
                        initialValue: record.hxtsyl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "蛰合剂使用量",
                        paramName: "zhjsyl",
                        // key: "zhjsyl",
                        initialValue: record.zhjsyl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "炉渣产量",
                        paramName: "lzcl",
                        // key: "lzcl",
                        initialValue: record.lzcl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                    {
                        type: 'input',
                        label: "飞灰产量",
                        paramName: "fhcl",
                        // key: "fhcl",
                        initialValue: record.fhcl,
                        rules: [{ ...config.reg.required }],
                        style: { width: 270 },
                    },
                ]
            })

        }


        console.log(record)
        this.setState({
            addModal: true,
            footerShow: true,
            modalTitle: '编辑',
            id: record.id,
            type:v
        })
    };


    // 分页
    onChangePage = (page, size) => {//分页

        this.setState({
            pageSize: size,
            pageIndex: page,
        }, () => {
            this.setTimeAndSearch(this.state.params, page, size);
        })
    };

    onChangePage1 = (page, size) => {//改变最大条数

        this.setState({
            pageSize: size,
            pageIndex: 1
        }, () => {
            this.setTimeAndSearch(this.state.params, 1, size);
        })
    };

    setTimeAndSearch = (val, pageIndex, row) => {
        this.setState({
            spinning: true,
            pageIndex,
            pageSize: row
        })

        let params = {
            kpiType: val.kpiType,
            page: this.state.pageIndex,
            rows: this.state.pageSize,
            monthStr: val.monthStr
        }

        request({
            url: '/sx-client/sx/indicator/fillInFromPagingQuery',
            method: 'POST',
            data: params
        }).then(data => {
            console.log(data)
            if (data.rc === 0) {
                this.setState({
                    dataSource: data.ret.items,
                    total: data.ret.count,
                    params
                })
            } else {
                message.warning(`${data.err}`)
            }
        })

    };





    onEdit = (text, record, index) => {//编辑
        console.log(text, record, index)
        this.state.dataSource[index].flag = true
        this.setState({
            dataSource: this.state.dataSource
        })
    }






    // modal保存
    ModalOk = (val) => {
        val.id = this.state.id
        if(this.state.type == '经济指标'){
            request({
                url: '/sx-client/sx/jjzbConfig/updateJjzbConfig',
                method: 'POST',
                data: val
            }).then(data => {
                if(data.rc === 0) {
                    message.success('修改成功!')
                }else{
                    message.warning(data.err)
                }

            })
        }

        if(this.state.type == '单产单耗'){
            request({
                url: '/sx-client/sx/dcdhzbconfig/updateDcdhzbConfig',
                method: 'POST',
                data: val
            }).then(data => {
                if(data.rc === 0) {
                    message.success('修改成功!')
                }else{
                    message.warning(data.err)
                }

            })
        }

        if(this.state.type == '物耗能耗'){
            request({
                url: '/sx-client/sx/whnhzbConfig/updateWhnhzbConfig',
                method: 'POST',
                data: val
            }).then(data => {
                if(data.rc === 0) {
                    message.success('修改成功!')
                }else{
                    message.warning(data.err)
                }

            })
        }

        this.getList()
        this.setState({
            addModal:false
        })




    }

    // 取消保存
    ModalCancel = (type) => {
        let t = this;
        t.setState({
            [type]: false,
            modalBtnLoading: false
        })
    };

    //重置
    ResetForm = () => {
        this.setState({
            pageSize: 10,
            pageIndex: 1,
        })
        setTimeout(() => {
            this.onSubmit(1, 10)
        }, 500)
    }

    render() {

        const { dataSource_dndh,dataSource_whnh,options, dataSource, pageSize, pageIndex, total, columns, addModal, modalTitle, footerShow, columns_dcdh, columns_whnh } = this.state

        let width = document.body.clientWidth;
        const height = document.body.clientHeight;
        let containerHeight = '25vh';
        let tableHeight = 330;
        if (width > 1367) {
            tableHeight = 630;
            containerHeight = '25vh';
        }


        const items = [
            {
                type: 'select',
                label: '指标类型',
                paramName: 'kpiType',
                options: [
                    { text: '清能环保', value: '1' },
                    { text: '再生能源', value: '2' },
                    { text: '维尔利', value: '3' },
                    { text: '清运公司', value: '4' },
                ],
            },
        ];
        return (

            <div className={styles.warp}>
                {
                    addModal &&
                    <AddModal
                        // dataTypes={dataTypes}
                        width={600}
                        visible={addModal}
                        title={modalTitle}
                        // modalBtnLoading={modalBtnLoading}
                        footerShow={footerShow}
                        onModalSave={this.ModalOk.bind(this)}
                        onCancel={this.ModalCancel.bind(this, 'addModal')}
                        // selectedChange={this.selectedChange}
                        moddleArr={this.state.moddleArr}

                    />
                }
                <Filtrate
                    items={items}
                    ref={ref => { this.f1 = ref }}
                    submit={this.onSubmit.bind(this, 1, 10)}
                    ResetForm={this.ResetForm}
                />

                <Container
                    style={{ height: containerHeight, position: "relative", overflow: 'auto' }}
                // header={true}
                >
                    <div className={styles.title}>
                        <div style={{ display: 'flex', alignItems: 'center' }}><span className={styles.ciler}></span> 经济指标</div>
                    </div>
                    <MyTable
                        columns={columns}
                        scroll={{ y: height - tableHeight }}
                        dataSource={PublicService.transformArrayData(dataSource, true, true, pageIndex, pageSize)}
                        pagination={false}
                    />
                </Container>

                <Container
                    style={{ height: containerHeight, position: "relative", overflow: 'auto', margin: '10px 0px' }}
                // header={true}
                >
                    <div className={styles.title}>
                        <div style={{ display: 'flex', alignItems: 'center' }}><span className={styles.ciler}></span> 物耗能耗指标</div>
                    </div>
                    <MyTable
                        columns={columns_whnh}
                        scroll={{ y: height - tableHeight }}
                        dataSource={PublicService.transformArrayData(dataSource_whnh, true, true, pageIndex, pageSize)}
                        pagination={false}
                    />
                </Container>

                <Container
                    style={{ height: containerHeight, position: "relative", overflow: 'auto' }}
                // header={true}
                >
                    <div className={styles.title}>
                        <div style={{ display: 'flex', alignItems: 'center' }}><span className={styles.ciler}></span> 单产单耗指标</div>
                    </div>
                    <MyTable
                        columns={columns_dcdh}
                        scroll={{ y: height - tableHeight }}
                        dataSource={PublicService.transformArrayData(dataSource_dndh, true, true, pageIndex, pageSize)}
                        pagination={false}
                    />
                </Container>

            </div>
        )
    }


}

export default connect()(Dbcspz)